<?php
class Ascii {
	function decode($str) {
		$flag = "&#";
		$pos = strpos ( $str, $flag );
		if ($pos === false) {
			return $str;
		} else {
			preg_match_all ( "/([0-9]{2,5})/", $str, $a );
			$a = $a [0];
			foreach ( $a as $dec ) {
				if ($dec < 128) {
					$utf .= chr ( $dec );
				} elseif ($dec < 2048) {
					$utf .= chr ( 192 + (($dec - ($dec % 64)) / 64) );
					$utf .= chr ( 128 + ($dec % 64) );
				} else {
					$utf .= chr ( 224 + (($dec - ($dec % 4096)) / 4096) );
					$utf .= chr ( 128 + ((($dec % 4096) - ($dec % 64)) / 64) );
					$utf .= chr ( 128 + ($dec % 64) );
				}
			}
			return $utf;
		}
	}
}
?>